//
//  LZFTabBarController.m
//  LZFBuDieJie
//
//  Created by 梁梓烽 on 16/6/21.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "LZFTabBarController.h"
#import "LZFEssenceController.h"
#import "UIImage+Render.h"
#import "LZFNavgationController.h"
#import "LZFNewController.h"
#import "LZFFriendTrendVC.h"
#import "LZFMineVC.h"
#import "LZFTabBar.h"


@interface LZFTabBarController ()
@property(nonatomic,strong)NSMutableArray *tabBarItemArray;
@end

@implementation LZFTabBarController

-(NSMutableArray *)tabBarItemArray
{
    if (_tabBarItemArray==nil) {
        _tabBarItemArray=[NSMutableArray new];
    }
    
    return _tabBarItemArray;
}


+(void)load
{
    //拿到当前类的tabbaritem
    UITabBarItem *tabBarItem=[UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    
    //设置tabbaritem的字体大小,只要在normal状态下才有效
    NSMutableDictionary *dic=[NSMutableDictionary new];
    //dic[NSForegroundColorAttributeName]=[UIColor blackColor];
    dic[NSFontAttributeName]=[UIFont systemFontOfSize:13];
    
    [tabBarItem setTitleTextAttributes:dic forState:UIControlStateNormal];
    
    //设置tabbarbutton选中状态下title的颜色
    NSMutableDictionary *dic1=[NSMutableDictionary new];
    dic1[NSForegroundColorAttributeName]=[UIColor blackColor];

    [tabBarItem setTitleTextAttributes:dic1 forState:UIControlStateSelected];
}



-(void)viewDidLoad
{
    //添加子控制器
    [self setUp];
    
  
    
    //创建自定义tabbar
    LZFTabBar  *lzfTabBar=[[LZFTabBar alloc]init];
    
  //kvc为tabbarcontroller赋值
    [self setValue:lzfTabBar forKey:@"tabBar"];
    
   
    
    
}

#pragma mark -添加子控制器
-(void)setUp{

    //精华
    LZFEssenceController *essenceVC=[[LZFEssenceController alloc]init];
    [self addOneChildViewController:essenceVC image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon" title:@"精华"];
    
    //新帖
    LZFNewController *newVC=[[LZFNewController alloc]init];
    [self addOneChildViewController:newVC image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon" title:@"新帖"];
    
    
    //关注
    
    LZFFriendTrendVC *friendTrendVC=[[LZFFriendTrendVC alloc]init];
    [self addOneChildViewController:friendTrendVC image:@"tabBar_friendTrends_icon" selectImage:@"tabBar_friendTrends_click_icon" title:@"关注"];
    
    
    //我
  //  LZFMineVC *mineVC=[[LZFMineVC alloc]init];
    
    UIStoryboard *sb=[UIStoryboard storyboardWithName:@"LZFMineVC" bundle:nil];
    LZFMineVC *mineVC= [sb instantiateInitialViewController];
    
    [self addOneChildViewController:mineVC image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon" title:@"我"];
    
    

}

-(void)addOneChildViewController:(UIViewController *)vc  image:(NSString *)image selectImage:(NSString *)selectImage  title:(NSString *)title
{
    
    vc.tabBarItem.image=[UIImage renderImageWithName:image];
    vc.tabBarItem.selectedImage=[UIImage renderImageWithName:selectImage];
    vc.tabBarItem.title=title;
    //记录每个vc的tabbaritem,为了传递给lzftabbar
    [self.tabBarItemArray addObject:vc.tabBarItem];
    
    LZFNavgationController *navVC=[[LZFNavgationController alloc]initWithRootViewController:vc];
   [self addChildViewController:navVC];
    
}




@end
